package com.miracle.main.module.mvp.ui.fragment;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.FloatingActionButton;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;

import com.miracle.basemvp.base.BaseFragment;
import com.miracle.basemvp.base.BaseResponse;
import com.miracle.basemvp.base.state.StateController;
import com.miracle.basemvp.di.component.AppComponent;
import com.miracle.common.base.BaseListFragment;
import com.miracle.common.view.RefreshView;
import com.miracle.main.R;
import com.miracle.main.R2;
import com.miracle.main.adapter.GlideImageLoader;
import com.miracle.main.adapter.SecreteAdapter;
import com.miracle.main.module.di.component.DaggerSecretComponent;
import com.miracle.main.module.di.module.SecretModule;
import com.miracle.main.module.mvp.contract.SecretContract;
import com.miracle.main.module.mvp.entity.bean.SecretBean;
import com.miracle.main.module.mvp.entity.request.SecretListRequest;
import com.miracle.main.module.mvp.presenter.SecretPresenter;
import com.miracle.main.module.mvp.ui.activity.AddSecretActivity;
import com.scwang.smartrefresh.layout.SmartRefreshLayout;
import com.trello.rxlifecycle2.LifecycleProvider;
import com.youth.banner.Banner;

import java.util.ArrayList;
import java.util.List;

import javax.inject.Inject;

import butterknife.BindView;
import butterknife.OnClick;
import retrofit2.http.Body;

/**
 * com.miracle.main.module.mvp.ui.fragment
 * (c)2018 AIR Times Inc. All rights reserved.
 *
 *
 * @author WangJQ
 * @version 1.0
 * @date 2018/7/2 18:04
 * @see com.miracle.main.module.mvp.ui.fragment
 */
public class SecretFragments extends BaseFragment<SecretPresenter> implements RefreshView.RefreshViewListener<SecretBean> {

    @BindView(R2.id.btn)
    FloatingActionButton mBtn;

    RefreshView<SecretBean,Object> mRefreshView;
    @BindView(R2.id.container)
    LinearLayout mLLContainer;

    @Inject
    SecreteAdapter mAdapter;
    @Inject
    ArrayList<SecretBean> mList;

    @Override
    public int setLayoutId(@Nullable Bundle bundle) {
        return R.layout.cloud_fragment_secret_2;
    }

    @Override
    public void setDaggerComponent(AppComponent appComponent) {
//        DaggerSecretComponent
//                .builder()
//                .appComponent(appComponent)
//                .secretModule(new SecretModule(this))
//                .build()
//                .inject(this);
    }

    @Override
    public void init(@Nullable Bundle bundle) {

    }

    private void initRefreshView() {
        mRefreshView = new RefreshView<>(mContext, mList, mAdapter);
        mLLContainer.addView(mRefreshView, new LinearLayout.LayoutParams(ViewGroup.LayoutParams
                .MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
        mRefreshView.setmRefreshListener(this);
        mRefreshView.onStart();
    }

    @Override
    public void initView() {
    }

    @Override
    public void initData() {
        initRefreshView();
    }

    @Override
    public void onRequest(LifecycleProvider<com.trello.rxlifecycle2.android.FragmentEvent>
                                  lifecycleProvider) {

    }

    @OnClick(R2.id.btn)
    public void onViewClicked(View view) {
        int id = view.getId();
        if (id == R.id.btn) {
            startActivity(new Intent(mContext, AddSecretActivity.class));
        }
    }

    @Override
    public void onRequestData() {
        mPresenter.getList(providerEvent(), new SecretListRequest(), mRefreshView);
    }

    @Override
    public void observerCallback(BaseResponse<SecretBean> baseResponse, RefreshView<SecretBean, Object> refreshView) {
//        refreshView.onComplete();
    }


//    @Override
//    public void showData(SecretBean secretBean) {
//
//    }
}
